package com.jeesite.huawei.ocr.demo;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.ocr.v1.OcrClient;
import com.huaweicloud.sdk.ocr.v1.model.AutoClassificationRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.BankcardRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.BusinessCardRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.BusinessLicenseRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.DriverLicenseRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.FlightItineraryRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.GeneralTableRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.GeneralTextRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.HandwritingRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.IdCardRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.InsurancePolicyRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.LicensePlateRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.MvsInvoiceRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.PassportRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.QualificationCertificateRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.QuotaInvoiceRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeAutoClassificationRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeAutoClassificationResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeBankcardRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeBankcardResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeBusinessCardRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeBusinessCardResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeBusinessLicenseRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeBusinessLicenseResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeDriverLicenseRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeDriverLicenseResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeFlightItineraryRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeFlightItineraryResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeGeneralTableRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeGeneralTableResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeGeneralTextRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeGeneralTextResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeHandwritingRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeHandwritingResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeIdCardRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeIdCardResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeInsurancePolicyRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeInsurancePolicyResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeLicensePlateRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeLicensePlateResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeMvsInvoiceRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeMvsInvoiceResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizePassportRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizePassportResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeQualificationCertificateRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeQualificationCertificateResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeQuotaInvoiceRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeQuotaInvoiceResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTaxiInvoiceRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTaxiInvoiceResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTollInvoiceRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTollInvoiceResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTrainTicketRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTrainTicketResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTransportationLicenseRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeTransportationLicenseResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeVatInvoiceRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeVatInvoiceResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeVehicleLicenseRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeVehicleLicenseResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeVinRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeVinResponse;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeWebImageRequest;
import com.huaweicloud.sdk.ocr.v1.model.RecognizeWebImageResponse;
import com.huaweicloud.sdk.ocr.v1.model.TaxiInvoiceRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.TollInvoiceRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.TrainTicketRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.TransportationLicenseRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.VatInvoiceRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.VehicleLicenseRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.VinRequestBody;
import com.huaweicloud.sdk.ocr.v1.model.WebImageRequestBody;
import com.jeesite.huawei.ocr.OcrRegion;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Demo {
    private static final Logger LOGGER = LoggerFactory.getLogger(Demo.class.getName());

    private static final String IMAGE_BASE64 = "<YOUR IMAGE_BASE64>";

    public static void main(String[] args) {
        // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险，建议在配置文件或者环境变量中密文存放，使用时解密，确保安全；
        // 本示例以ak和sk保存在环境变量中来实现身份认证为例，运行示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。
        String ak = System.getenv("HUAWEICLOUD_SDK_AK");
        String sk = System.getenv("HUAWEICLOUD_SDK_SK");


        // Init Auth Info
        ICredential credential = getCredential(ak, sk);

        // create ocrClient
        OcrClient ocrClient = getClient(OcrRegion.CN_NORTH_4, credential);

        // 通用文字识别
        generalText(ocrClient, IMAGE_BASE64);

        // 通用表格识别
        generalTable(ocrClient, IMAGE_BASE64);

        // 身份证识别
        idCard(ocrClient, IMAGE_BASE64);

        // 银行卡识别
        bankcard(ocrClient, IMAGE_BASE64);

        // 智能分类识别
        autoClassification(ocrClient, IMAGE_BASE64);

        // 增值税发票识别
        vatInvoice(ocrClient, IMAGE_BASE64);

        // 定额发票识别
        quotaInvoice(ocrClient, IMAGE_BASE64);

        // 手写文字识别
        handwriting(ocrClient, IMAGE_BASE64);

        // 行驶证识别
        vehicleLicense(ocrClient, IMAGE_BASE64);

        // 道路运输证识别
        transportationLicense(ocrClient, IMAGE_BASE64);

        // 出租车发票识别
        taxiInvoice(ocrClient, IMAGE_BASE64);

        // 车辆通行费发票识别
        tollInvoice(ocrClient, IMAGE_BASE64);

        // 机动车销售发票识别
        mvsInvoice(ocrClient, IMAGE_BASE64);

        // 车牌识别
        licensePlate(ocrClient, IMAGE_BASE64);

        // 飞机行程单识别
        flightItinerary(ocrClient, IMAGE_BASE64);

        // 营业执照识别
        businessLicense(ocrClient, IMAGE_BASE64);

        // 网络图片识别
        webImage(ocrClient, IMAGE_BASE64);

        // 驾驶证识别
        driverLicense(ocrClient, IMAGE_BASE64);

        // 名片识别
        businessCard(ocrClient, IMAGE_BASE64);

        // 火车票识别
        trainTicket(ocrClient, IMAGE_BASE64);

        // VIN码识别
        vin(ocrClient, IMAGE_BASE64);

        // 护照识别
        passport(ocrClient, IMAGE_BASE64);

        // 保险单识别
        insurancePolicy(ocrClient, IMAGE_BASE64);

        // 道路运输从业资格证识别
        qualificationCertificate(ocrClient, IMAGE_BASE64);
    }

    public static ICredential getCredential(String ak, String sk) {
        return new BasicCredentials().withAk(ak).withSk(sk);
    }

    public static OcrClient getClient(Region region, ICredential auth) {
        return OcrClient.newBuilder().withCredential(auth).withRegion(region).build();
    }

    private static void insurancePolicy(OcrClient ocrClient, String image) {
        RecognizeInsurancePolicyRequest request = new RecognizeInsurancePolicyRequest();
        InsurancePolicyRequestBody body = new InsurancePolicyRequestBody();
        body.withDetectDirection(true);
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeInsurancePolicyResponse response = ocrClient.recognizeInsurancePolicy(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void qualificationCertificate(OcrClient ocrClient, String image) {
        RecognizeQualificationCertificateRequest request = new RecognizeQualificationCertificateRequest();
        QualificationCertificateRequestBody body = new QualificationCertificateRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeQualificationCertificateResponse response = ocrClient.recognizeQualificationCertificate(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
           LOGGER.error(String.valueOf(e.getHttpStatusCode()));
           LOGGER.error(e.getErrorCode());
           LOGGER.error(e.getErrorMsg());
        }
    }

    private static void passport(OcrClient ocrClient, String image) {
        RecognizePassportRequest request = new RecognizePassportRequest();
        PassportRequestBody body = new PassportRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizePassportResponse response = ocrClient.recognizePassport(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void vin(OcrClient ocrClient, String image) {
        RecognizeVinRequest request = new RecognizeVinRequest();
        VinRequestBody body = new VinRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeVinResponse response = ocrClient.recognizeVin(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void trainTicket(OcrClient ocrClient, String image) {
        RecognizeTrainTicketRequest request = new RecognizeTrainTicketRequest();
        TrainTicketRequestBody body = new TrainTicketRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeTrainTicketResponse response = ocrClient.recognizeTrainTicket(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void businessCard(OcrClient ocrClient, String image) {
        RecognizeBusinessCardRequest request = new RecognizeBusinessCardRequest();
        BusinessCardRequestBody body = new BusinessCardRequestBody();
        body.withDetectDirection(true);
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeBusinessCardResponse response = ocrClient.recognizeBusinessCard(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void driverLicense(OcrClient ocrClient, String image) {
        RecognizeDriverLicenseRequest request = new RecognizeDriverLicenseRequest();
        DriverLicenseRequestBody body = new DriverLicenseRequestBody();
        body.withReturnIssuingAuthority(true);
        body.withSide("front");
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeDriverLicenseResponse response = ocrClient.recognizeDriverLicense(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void webImage(OcrClient ocrClient, String image) {
        RecognizeWebImageRequest request = new RecognizeWebImageRequest();
        WebImageRequestBody body = new WebImageRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeWebImageResponse response = ocrClient.recognizeWebImage(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void businessLicense(OcrClient ocrClient, String image) {
        RecognizeBusinessLicenseRequest request = new RecognizeBusinessLicenseRequest();
        BusinessLicenseRequestBody body = new BusinessLicenseRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeBusinessLicenseResponse response = ocrClient.recognizeBusinessLicense(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void flightItinerary(OcrClient ocrClient, String image) {
        RecognizeFlightItineraryRequest request = new RecognizeFlightItineraryRequest();
        FlightItineraryRequestBody body = new FlightItineraryRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeFlightItineraryResponse response = ocrClient.recognizeFlightItinerary(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void licensePlate(OcrClient ocrClient, String image) {
        RecognizeLicensePlateRequest request = new RecognizeLicensePlateRequest();
        LicensePlateRequestBody body = new LicensePlateRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeLicensePlateResponse response = ocrClient.recognizeLicensePlate(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void mvsInvoice(OcrClient ocrClient, String image) {
        RecognizeMvsInvoiceRequest request = new RecognizeMvsInvoiceRequest();
        MvsInvoiceRequestBody body = new MvsInvoiceRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeMvsInvoiceResponse response = ocrClient.recognizeMvsInvoice(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void tollInvoice(OcrClient ocrClient, String image) {
        RecognizeTollInvoiceRequest request = new RecognizeTollInvoiceRequest();
        TollInvoiceRequestBody body = new TollInvoiceRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeTollInvoiceResponse response = ocrClient.recognizeTollInvoice(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void taxiInvoice(OcrClient ocrClient, String image) {
        RecognizeTaxiInvoiceRequest request = new RecognizeTaxiInvoiceRequest();
        TaxiInvoiceRequestBody body = new TaxiInvoiceRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeTaxiInvoiceResponse response = ocrClient.recognizeTaxiInvoice(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void transportationLicense(OcrClient ocrClient, String image) {
        RecognizeTransportationLicenseRequest request = new RecognizeTransportationLicenseRequest();
        TransportationLicenseRequestBody body = new TransportationLicenseRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeTransportationLicenseResponse response = ocrClient.recognizeTransportationLicense(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void vehicleLicense(OcrClient ocrClient, String image) {
        RecognizeVehicleLicenseRequest request = new RecognizeVehicleLicenseRequest();
        VehicleLicenseRequestBody body = new VehicleLicenseRequestBody();
        body.withReturnIssuingAuthority(true);
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeVehicleLicenseResponse response = ocrClient.recognizeVehicleLicense(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void handwriting(OcrClient ocrClient, String image) {
        RecognizeHandwritingRequest request = new RecognizeHandwritingRequest();
        HandwritingRequestBody body = new HandwritingRequestBody();
        body.withDetectDirection(true);
        body.withQuickMode(true);
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeHandwritingResponse response = ocrClient.recognizeHandwriting(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void quotaInvoice(OcrClient ocrClient, String image) {
        RecognizeQuotaInvoiceRequest request = new RecognizeQuotaInvoiceRequest();
        QuotaInvoiceRequestBody body = new QuotaInvoiceRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeQuotaInvoiceResponse response = ocrClient.recognizeQuotaInvoice(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }


    private static void vatInvoice(OcrClient ocrClient, String image) {
        RecognizeVatInvoiceRequest request = new RecognizeVatInvoiceRequest();
        VatInvoiceRequestBody body = new VatInvoiceRequestBody();
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeVatInvoiceResponse response = ocrClient.recognizeVatInvoice(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void autoClassification(OcrClient ocrClient, String image) {
        RecognizeAutoClassificationRequest request = new RecognizeAutoClassificationRequest();
        AutoClassificationRequestBody requestBody = new AutoClassificationRequestBody();
        requestBody.withImage(image);
        request.setBody(requestBody);
        try {
            RecognizeAutoClassificationResponse response = ocrClient.recognizeAutoClassification(request);
            System.out.println(response);
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void bankcard(OcrClient ocrClient, String image) {
        RecognizeBankcardRequest recognizeBankcardRequest = new RecognizeBankcardRequest();
        BankcardRequestBody bankcardRequestBody = new BankcardRequestBody();
        bankcardRequestBody.setImage(image);
        recognizeBankcardRequest.setBody(bankcardRequestBody);
        try {
            RecognizeBankcardResponse response = ocrClient.recognizeBankcard(recognizeBankcardRequest);
            System.out.println(response);
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void idCard(OcrClient ocrClient, String image) {
        RecognizeIdCardRequest request = new RecognizeIdCardRequest();
        IdCardRequestBody body = new IdCardRequestBody();
        body.withReturnVerification(true);
        body.withSide("front");
        body.withImage(image);
        request.withBody(body);
        try {
            RecognizeIdCardResponse response = ocrClient.recognizeIdCard(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void generalTable(OcrClient ocrClient, String image) {
        RecognizeGeneralTableRequest request = new RecognizeGeneralTableRequest();
        GeneralTableRequestBody requestBody = new GeneralTableRequestBody();
        requestBody.withImage(image);
        request.withBody(requestBody);
        try {
            RecognizeGeneralTableResponse response = ocrClient.recognizeGeneralTable(request);
            System.out.println(response.toString());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }

    private static void generalText(OcrClient ocrClient, String image) {
        RecognizeGeneralTextRequest recognizeGeneralTextRequest = new RecognizeGeneralTextRequest();
        GeneralTextRequestBody requestBody = new GeneralTextRequestBody();
        requestBody.setImage(image);
        recognizeGeneralTextRequest.setBody(requestBody);
        try {
            RecognizeGeneralTextResponse textResponse = ocrClient.recognizeGeneralText(recognizeGeneralTextRequest);
            System.out.println(textResponse.getResult());
        } catch (ConnectionException | RequestTimeoutException e) {
            LOGGER.error(e.toString());
        } catch (ServiceResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getErrorMsg());
        }
    }
}

